<?
	class Tmysql
	{
		var $conn_id; //contains  the link identifier to the db
		var $sql_query; // contains the query
		var $sql_err;
		var $sql_res; //contains the result of mysql_query to db
		var $num_rows;// the number of rows in query result

		function  Tmysql( $db = '' ) //Constructor
		{
			if( defined('PARAM_'.$db.'_SQL_LOGIN') ) 
            { 
                $this->conn_id = @mysql_connect( constant('PARAM_'.$db.'_SQL_HOST'), constant('PARAM_'.$db.'_SQL_LOGIN'), constant('PARAM_'.$db.'_SQL_PASSWD'), true ) or die( ff ?mysql_error():'' ) ;
            }
            else $this->conn_id = @mysql_connect( PARAM_SQL_HOST, PARAM_SQL_LOGIN, PARAM_SQL_PASSWD, true ) or die( PARAM_DEBAG_STATUS?mysql_error():'' ) ;
            @mysql_query('SET NAMES utf8', $this->conn_id);
            if( $db and defined('PARAM_'.$db.'_SQL_DB_NAME') )
          	{ @mysql_select_db (constant('PARAM_'.$db.'_SQL_DB_NAME'), $this->conn_id ) or die( PARAM_DEBAG_STATUS?mysql_error():'') ; }
          	else @mysql_select_db ( PARAM_SQL_DB_NAME, $this->conn_id ) or die( PARAM_DEBAG_STATUS?mysql_error():'') ;
		}

		function sql_exe( $value = '' )
		{
        	$value = $value?$value:$this->sql_query;
        	$this->sql_res  = @mysql_query ( $value , $this->conn_id );
        	if ( $this->sql_err = @mysql_error () ) die( PARAM_DEBAG_STATUS?($this->sql_err .'<br>'. $value):'' );
        	$this->num_rows = @mysql_num_rows( $this->sql_res );
        	return( $this->sql_res );
		}

		function fetch() { return( mysql_fetch_array( $this->sql_res ) ); }
	}
?>